package com.ht.modules.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ht.modules.system.entity.DataRule;
import com.ht.modules.system.entity.DataRuleVo;
import com.ht.modules.system.mapper.DataRuleMapper;
import com.ht.modules.system.service.IDataRuleService;
import com.ht.utils.DicConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * x数据规则

 */
@Service
public class DataRuleServiceImpl extends ServiceImpl<DataRuleMapper, DataRule> implements IDataRuleService {

	@Autowired
	private DataRuleMapper dataRuleMapper;

	/**
	 * 重写的list列表方法
	 */
	@Override
	public Page<DataRuleVo> list(Page<DataRuleVo> page, DataRuleVo dataRuleVo, String column, String order) {
		 return page.setRecords(dataRuleMapper.list(page, dataRuleVo, column, order));
	}

	/**
     * 新增方法
     */
    @Override
    public void add(DataRule dataRule) {
        dataRule.setDelFlag(DicConstants.DEL_FLAG_WSC);
        this.save(dataRule);
    }

    /**
     * 编辑方法
     */
    @Override
    public void edit(DataRule dataRule) {
        DataRule dataRuleEntity = this.getById(dataRule.getId());
        if (dataRuleEntity == null){
            throw new RuntimeException("未找到对应实体！");
        }
        this.updateById(dataRule);
    }

    /**
     * 删除方法（逻辑删除）
     */
    @Override
    public void delete(String id) {
        DataRule dataRule = this.getById(id);
        if (dataRule == null){
            throw new RuntimeException("未找到对应实体！");
        }
        dataRule.setDelFlag(DicConstants.DEL_FLAG_YSC);
        this.updateById(dataRule);
    }

    /**
     * 批量删除方法（逻辑删除）
     */
    @Override
    public void deleteBatch(String ids) {
        if (ids == null || "".equals(ids.trim())){
            throw new RuntimeException("参数不识别！");
        }
        dataRuleMapper.updateBatchByIds("del_flag", DicConstants.DEL_FLAG_YSC, ids.split(","));
    }

    /**
     * 通过id查询方法
     */
    @Override
    public DataRule queryById(String id) {
        DataRule dataRule = this.getById(id);
        if (dataRule == null){
            throw new RuntimeException("未找到对应实体！");
        }
        return dataRule;
    }

	@Override
	public List<DataRule> listUrlConcatStr(String str) {
		return dataRuleMapper.listUrlConcatStr(str);
	}

}
